﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

namespace 城市天然气管道风险管理与决策系统
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
        }

        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void 基本信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_1_1 = new Form_menu_1_1();
            form_1_1.ShowDialog();
        }

        private void 状态信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_1_2 = new Form_menu_1_2();
            form_1_2.ShowDialog();
        }

        private void 维修信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_1_3 = new Form_menu_1_3();
            form_1_3.ShowDialog();
        }

        private void 事故信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_1_4 = new Form_menu_1_4();
            form_1_4.ShowDialog();
        }

        private void 防控预警等级分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_2 = new Form_menu_2();
            form_2.ShowDialog();
        }

        private void 数据备份ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.FileName = "Data_Backup.bin";
            saveFileDialog1.Filter = "(二进制文件)|*.bin";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                IFormatter formatter = new BinaryFormatter();
                Stream stream = new FileStream("Data_Backup.bin", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
                formatter.Serialize(stream, GlobalData.pipelines);
                stream.Close();
                MessageBox.Show("备份成功！");
            }
        }

        private void 数据恢复ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Stream stream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.None);
                try
                {
                    GlobalData.pipelines.Clear();
                    IFormatter formatter = new BinaryFormatter();
                    GlobalData.pipelines = (List<Pipeline>)formatter.Deserialize(stream);
                    stream.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("未读取到管道数据");
                    stream.Close();
                }
            }
        }

        private void 帮助信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://xauat.site/PCEDU/Guide.jsp");
        }

        private void 关于软件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://xauat.site/PCEDU/Copyright.jsp");
        }

        private void 应急决策系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form_3 = new Form_menu_3();
            form_3.ShowDialog();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {

        }
    }
}
